<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 商品列表
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-button type="primary" icon="el-icon-search" @click="handleAddConsumer">添加</el-button>
            <el-table
                    :data="consumerData"
                    border
                    class="table"
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                    @selection-change="handleSelectionChange"
            >
                <el-table-column prop="Consumer_id" label="顾客编号" width="100" align="center"></el-table-column>
                <el-table-column prop="Consumer_name" label="顾客姓名"></el-table-column>
                <el-table-column prop="Consumer_address" label="顾客地址"></el-table-column>
                <el-table-column prop="Consumer_postcode" label="邮政编码"></el-table-column>
                <el-table-column prop="Consumer_phone" label="电话"></el-table-column>
                <el-table-column label="操作" width="180" align="center">
                    <template #default="scope">
                        <el-button
                                type="primary"
                                icon="el-icon-delete"
                                class="red"
                                @click="handleDelete(scope.row)"
                        >删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <!-- 添加弹出框 -->
        <el-dialog title="购买" v-model="addVisible" width="30%">
            <el-form ref="form" :model="form" label-width="70px">
                <el-form-item label="顾客编号">
                    <el-input v-model="tempconsumerData.Consumer_id"></el-input>
                </el-form-item>
                <el-form-item label="顾客姓名">
                    <el-input v-model="tempconsumerData.Consumer_name"></el-input>
                </el-form-item>
                <el-form-item label="顾客地址">
                    <el-input v-model="tempconsumerData.Consumer_address"></el-input>
                </el-form-item>
                <el-form-item label="邮政编码">
                    <el-input v-model="tempconsumerData.Consumer_postcode"></el-input>
                </el-form-item>
                <el-form-item label="电话">
                    <el-input v-model="tempconsumerData.Consumer_phone"></el-input>
                </el-form-item>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="buyVisible = false">取 消</el-button>
                    <el-button type="primary" @click="addconsumer">确 定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script>
    import {consumerdelete, fetchconsumerData} from "../api/index";
    import {addconsumer} from "../api/index";
    export default {
        name: "conusmerData",
        data() {
            return {
                consumerData: [],

                tempconsumerData: {},
                consumerdeletedata: {},
                query:{},
                multipleSelection: [],
                delList: [],
                addVisible: false,
                pageTotal: 0,

                idx: -1,
                id: -1
            };
        },
        created() {
            this.getData()
        },
        methods: {

            getData(){
                fetchconsumerData().then(res =>{console.info(res)
                    this.consumerData=res.data.value
                })
            },
            handleAddConsumer(){
                this.addVisible = true;
            },
            addconsumer() {
                this.addVisible = false;
                this.$message.success(`添加成功`);
                addconsumer(this.tempconsumerData).then(res =>{console.info(res)
                    console.log(this.tempconsumerData)
                    console.log(res)
                    window.location.reload()
                })
            },
            handleDelete(row) {
                this.consumerdeletedata = row
                consumerdelete(this.consumerdeletedata).then(res =>{console.info(res)
                    console.log(this.consumerdeletedata)
                    console.log(res)
                })
                window.location.reload()
            },
        }
    };
</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }
    .table {
        width: 100%;
        font-size: 14px;
    }
    .red {
        color: #ff0000;
    }
    .mr10 {
        margin-right: 10px;
    }
    .table-td-thumb {
        display: block;
        margin: auto;
        width: 40px;
        height: 40px;
    }
</style>
